package com.woniu.sharepark.config;

import com.woniu.sharepark.util.UploadImageUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.ResourceUtils;

import javax.annotation.PostConstruct;
import java.net.URLDecoder;

/**
 * @ClassName: UploadConfig
 * @Description: 此为上传图片工具类对应的配置类，主要用于将yml中的值传递给工具类
 * @Author: Zongjie.Li
 * @Date: 2019/6/5
 * @Version: 1.0
 **/

@Configuration
public class UploadConfig {

    @Value("${upload.location}")
    private String path;

    /**
    * 在配置类加载完成后执行，实现UploadImageUtil的参数初始化
    *
    * @return void
    * @Author Zongjie.Li
    * @Date 2019/6/5
    */
    @PostConstruct
    public void init(){
        try {
            UploadImageUtil.setSystemPath(URLDecoder.decode(ResourceUtils.getURL("classpath:").getPath(), "utf-8") + path);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
